﻿Imports ADOEntityKYC
Imports System.Data
Partial Class Form_KYC1T_02
    Inherits System.Web.UI.Page
    Dim KYCEntity As KYCEntities = New KYCEntities
    Dim ds As DataSet

    Dim uniqueID1 As String
    Dim BizType As String
    Dim PrefixTH As String
    Dim NameTh1 As String
    Dim NameEn1 As String
    Dim Nationality As String
    Dim Business1 As String
    Dim BizOther1 As String
    Dim Des1 As String
    Dim Business2 As String
    Dim BizOther2 As String
    Dim Des2 As String
    Dim Business3 As String
    Dim BizOther3 As String
    Dim Des3 As String
    Dim IncomeSource1 As String
    Dim IncomeSource2 As String
    Dim IncomeSource3 As String
    Dim Level As String
    Dim Reason As String

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        Response.AddHeader("Cache-control", "no-store, must-revalidate, private,no-cache")
        Response.AddHeader("Pragma", "no-cache")
        Response.AddHeader("Expires", "0")
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        ds = Session("ds")

        If Request.QueryString("Type") = 3 Then
            'If Request.QueryString("CUSTSEQ") = "" Then
            '    QueryString()
            '    bindingDataPNRisk()
            'Else
            bindingDataPN()
            'End If
        Else
            bindingData()
        End If

        userPrint()

        'Dim pageKey As RegistryKey = Registry.CurrentUser.OpenSubKey("software\microsoft\internet explorer\pagesetup", True)

        'pageKey.SetValue("footer", "")
        'pageKey.SetValue("header", "")
        ''pageKey.SetValue("margin_left", "")
        ''pageKey.SetValue("margin_top", "")
        'pageKey.Close()


        Response.Write("<script>")
        Response.Write("window.print()")
        Response.Write("</script>")

    End Sub

    Private Sub bindingData()

        Dim CUSTSEQ As Integer = Request.QueryString("CUSTSEQ")
        Dim KYCSEQ As Integer = Request.QueryString("KYCSEQ")
        Dim qryCust As Object

        qryCust = (From cust In KYCEntity.MCUSTOMER
          Join p In KYCEntity.MPREFIX On cust.THPREFIX Equals p.PREFIXCODE
         Join n In KYCEntity.MNATIONALITY On cust.NATIONALITY Equals n.NATIONCODE
         Group Join biz In KYCEntity.MBUSINESS On cust.BIZTYPE1 Equals biz.BIZCODE
         Into a = Group From leftA In a.DefaultIfEmpty
         Group Join incom1 In KYCEntity.MNATIONALITY On cust.INCOMESOURCE1 Equals incom1.NATIONCODE
         Into aa = Group From leftAA In aa.DefaultIfEmpty
         Group Join incom2 In KYCEntity.MNATIONALITY On cust.INCOMESOURCE2 Equals incom2.NATIONCODE
         Into b = Group From leftB In b.DefaultIfEmpty
         Group Join incom3 In KYCEntity.MNATIONALITY On cust.INCOMESOURCE3 Equals incom3.NATIONCODE
         Into c = Group From leftC In c.DefaultIfEmpty
         Where (cust.CUSTSEQ = CUSTSEQ)
         Select cust, p.PREFIXTH, n.NATIONALITYNAME, incomes1 = leftAA.COUNTYNAME,
         leftA.BIZNAME, incomes2 = leftB.COUNTYNAME, incomes3 = leftC.COUNTYNAME).ToList





        If Not qryCust.Count = 0 Then

            If qryCust(0).cust.THPREFIX = 160 Then
                lblPrefix1.Text = "X"
            ElseIf qryCust(0).cust.THPREFIX = 161 Then
                lblPrefix2.Text = "X"
            ElseIf qryCust(0).cust.THPREFIX = 205 Then
                lblPrefix3.Text = "X"
                'ElseIf qryCust(0).cust.THPREFIX = 54 Then
                '    lblPrefix4.Text = "X" 'ยังไม่ครบ
            Else
                lblPrefix5.Text = "X"
                lblPrefixOther.Text = qryCust(0).PREFIXTH
            End If

            lblTHName.Text = qryCust(0).cust.THFIRSTNAME
            ' lblENName.Text = qryCust(0).cust.ENFIRSTNAME.ToUpper

            If Not qryCust(0).cust.ENFIRSTNAME Is Nothing Then
                lblENName.Text = qryCust(0).cust.ENFIRSTNAME.ToUpper
            End If

            lblUniqueID.Text = qryCust(0).cust.UNIQUEID


            If qryCust(0).cust.BIZTYPE1 = 99 Then
                lblBiz.Text = qryCust(0).cust.BIZTYPEOTHER1
            Else
                lblBiz.Text = qryCust(0).BIZNAME
            End If

            lblNational.Text = convertThai(qryCust(0).NATIONALITYNAME)

            lblIncome.Text = convertThai(qryCust(0).incomes1)
            If Not qryCust(0).cust.INCOMESOURCE2 Is Nothing Then
                lblIncome.Text += ", " + convertThai(qryCust(0).incomes2)
            End If
            If Not qryCust(0).cust.INCOMESOURCE3 Is Nothing Then
                lblIncome.Text += ", " + convertThai(qryCust(0).incomes3)
            End If

            If Not qryCust(0).cust.NGOCHECK1 Is Nothing Then
                If qryCust(0).cust.NGOCHECK1 = 1 Then
                    lblNPO1.Text = "X"
                ElseIf qryCust(0).cust.NGOCHECK1 = 2 Then
                    lblNPO2.Text = "X"
                End If
            End If

            If Not qryCust(0).cust.COMPCHECK1 Is Nothing Then
                If qryCust(0).cust.COMPCHECK1 = 1 Then
                    lblRegis1.Text = "X"
                ElseIf qryCust(0).cust.COMPCHECK1 = 2 Then
                    lblRegis2.Text = "X"
                ElseIf qryCust(0).cust.COMPCHECK1 = 3 Then
                    lblRegis3.Text = "X"
                End If
            End If


            lblFormalAddr.Text = qryCust(0).cust.FORMALADDR
            lblFormalPhone.Text = qryCust(0).cust.FORMALPHONE1
            Dim tempSalary As Double
            tempSalary = qryCust(0).cust.SALARYPERMONTH()
            lblSalary.Text = String.Format("{0:n}", tempSalary)

            'If qryCust(0).cust.ISANSWERSARALY = 1 Then
            '    Dim tempSalary As Double
            '    tempSalary = qryCust(0).cust.SALARYPERMONTH()
            '    lblSalary.Text = String.Format("{0:n}", tempSalary)

            'Else
            '    lblSalary.Text = "-"
            'End If

            If lblNational.Text = "ไทย" Then
                lblChkNation1.Text = "X"
                lblNational.Text = ""
            Else
                lblChkNation2.Text = "X"

            End If

            If lblIncome.Text = "ไทย" Then
                lblChkIncome1.Text = "X"
                lblIncome.Text = ""
            Else
                lblChkIncome2.Text = "X"
            End If

            If Not qryCust(0).cust.CHECKADDRESS Is Nothing Then

                If qryCust(0).cust.CHECKADDRESS = 22 Or qryCust(0).cust.CHECKADDRESS = 25 Then
                    lblEv1.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 23 Or qryCust(0).cust.CHECKADDRESS = 21 Then
                    lblEv2.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 29 Then
                    lblEv3.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 30 Then
                    lblEv4.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 31 Then
                    lblEv5.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 32 Then
                    lblEv6.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 33 Then
                    lblEv7.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 34 Then
                    lblEv8.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 35 Then
                    lblEv9.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 36 Then
                    lblEv10.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 37 Then
                    lblEv11.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 38 Then
                    lblEv12.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 39 Then
                    lblEv13.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 40 Then
                    lblEv14.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 41 Then
                    lblEv15.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 42 Then
                    lblEv16.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 43 Then
                    lblEv17.Text = "X"
                ElseIf qryCust(0).cust.CHECKADDRESS = 44 Then
                    lblEv18.Text = "X"
                Else
                    lblEv19.Text = "X"
                End If
            End If
             
        End If


        qryCust = Nothing

    End Sub

    Private Sub bindingDataPN()

        Dim CUSTSEQ As Integer = Request.QueryString("CUSTSEQ")

 

        Dim qryCust = (From cust In KYCEntity.MCUSTOMER
                Join p In KYCEntity.MPREFIX On cust.THPREFIX Equals p.PREFIXCODE
               Join n In KYCEntity.MNATIONALITY On cust.NATIONALITY Equals n.NATIONCODE
               Group Join biz In KYCEntity.MBUSINESS On cust.BIZTYPE1 Equals biz.BIZCODE
               Into a = Group From leftA In a.DefaultIfEmpty
               Group Join incom1 In KYCEntity.MNATIONALITY On cust.INCOMESOURCE1 Equals incom1.NATIONCODE
               Into aa = Group From leftAA In aa.DefaultIfEmpty
               Group Join incom2 In KYCEntity.MNATIONALITY On cust.INCOMESOURCE2 Equals incom2.NATIONCODE
               Into b = Group From leftB In b.DefaultIfEmpty
               Group Join incom3 In KYCEntity.MNATIONALITY On cust.INCOMESOURCE3 Equals incom3.NATIONCODE
               Into c = Group From leftC In c.DefaultIfEmpty
               Where cust.CUSTSEQ = CUSTSEQ
               Select cust, p.PREFIXTH, n.NATIONALITYNAME, incomes1 = leftAA.COUNTYNAME,
               leftA.BIZNAME, incomes2 = leftB.COUNTYNAME, incomes3 = leftC.COUNTYNAME).ToList


        If Not qryCust.Count = 0 Then

            If qryCust(0).cust.THPREFIX = 160 Then
                lblPrefix1.Text = "X"
            ElseIf qryCust(0).cust.THPREFIX = 161 Then
                lblPrefix2.Text = "X"
            ElseIf qryCust(0).cust.THPREFIX = 205 Then
                lblPrefix3.Text = "X"
                'ElseIf qryCust(0).cust.THPREFIX = 54 Then
                '    lblPrefix4.Text = "X" 'ยังไม่ครบ
            Else
                lblPrefix5.Text = "X"
                lblPrefixOther.Text = qryCust(0).PREFIXTH
            End If

            lblTHName.Text = qryCust(0).cust.THFIRSTNAME
            'lblENName.Text = qryCust(0).cust.ENFIRSTNAME.ToUpper
            If Not qryCust(0).cust.ENFIRSTNAME Is Nothing Then
                lblENName.Text = qryCust(0).cust.ENFIRSTNAME.ToUpper
            End If

            lblUniqueID.Text = qryCust(0).cust.UNIQUEID

            If qryCust(0).cust.BIZTYPE1 = 99 Then
                lblBiz.Text = qryCust(0).cust.BIZTYPEOTHER1
            Else
                lblBiz.Text = qryCust(0).BIZNAME
            End If

            lblNational.Text = convertThai(qryCust(0).NATIONALITYNAME)

            lblIncome.Text = convertThai(qryCust(0).incomes1)
            If Not qryCust(0).cust.INCOMESOURCE2 Is Nothing Then
                lblIncome.Text += ", " + convertThai(qryCust(0).incomes2)
            End If
            If Not qryCust(0).cust.INCOMESOURCE3 Is Nothing Then
                lblIncome.Text += ", " + convertThai(qryCust(0).incomes3)
            End If

            If Not qryCust(0).cust.NGOCHECK1 Is Nothing Then
                If qryCust(0).cust.NGOCHECK1 = 1 Then
                    lblNPO1.Text = "X"
                ElseIf qryCust(0).cust.NGOCHECK1 = 2 Then
                    lblNPO2.Text = "X"
                End If
            End If

            If Not qryCust(0).cust.COMPCHECK1 Is Nothing Then
                If qryCust(0).cust.COMPCHECK1 = 1 Then
                    lblRegis1.Text = "X"
                ElseIf qryCust(0).cust.COMPCHECK1 = 2 Then
                    lblRegis2.Text = "X"
                ElseIf qryCust(0).cust.COMPCHECK1 = 3 Then
                    lblRegis3.Text = "X"
                End If
            End If

      
        End If


        qryCust = Nothing

    End Sub

    Private Sub userPrint()

        Dim convertDate As clsDateFormat = New clsDateFormat
        Dim clsSessionMenuRight As clsSessionMenuRight = New clsSessionMenuRight
        clsSessionMenuRight = Session("clsMenuRight")

        lblUserName.Text = clsSessionMenuRight.getEmpFirstName + "&nbsp;&nbsp;" + clsSessionMenuRight.getEmpLastName
        lblPrintDate.Text = convertDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, Now.Date)
        lblUserID.Text = clsSessionMenuRight.getUserName
        lblBranch.Text = clsSessionMenuRight.getBranchName
        convertDate = Nothing
        clsSessionMenuRight = Nothing

    End Sub

    Private Function convertThai(ByVal country As String) As String
        Dim str As String = ""
        If country = "THAI" Or country = "THAILAND" Then
            str = "ไทย"
        Else
            str = country
        End If

        Return str
    End Function


    'ยังไม่ใช้
    Private Sub QueryString()
        uniqueID1 = Request.QueryString("uniqueID").Trim
        BizType = Request.QueryString("BizType").Trim
        PrefixTH = Request.QueryString("PrefixTH").Trim
        NameTh1 = Request.QueryString("NameTh1").Trim
        NameEn1 = Request.QueryString("NameEn1").Trim
        Nationality = Request.QueryString("Nationality").Trim
        Business1 = Request.QueryString("Business1").Trim
        BizOther1 = Request.QueryString("BizOther1").Trim
        Des1 = Request.QueryString("Des1").Trim
        Business2 = Request.QueryString("Business2").Trim
        BizOther2 = Request.QueryString("BizOther2").Trim
        Des2 = Request.QueryString("Des2").Trim
        Business3 = Request.QueryString("Business3").Trim
        BizOther3 = Request.QueryString("BizOther3").Trim
        Des3 = Request.QueryString("Des3").Trim
        IncomeSource1 = Request.QueryString("IncomeSource1").Trim
        IncomeSource2 = Request.QueryString("IncomeSource2").Trim
        IncomeSource3 = Request.QueryString("IncomeSource3").Trim

        Level = Request.QueryString("RiskLevel").Trim
        Reason = Request.QueryString("Reason").Trim

    End Sub

    Private Sub bindingDataPNRisk()

        If PrefixTH = 1 Then
            lblPrefix1.Text = "X"
        ElseIf PrefixTH = 2 Then
            lblPrefix2.Text = "X"
        ElseIf PrefixTH = 3 Then
            lblPrefix3.Text = "X"
        ElseIf PrefixTH = 4 Then
            lblPrefix4.Text = "X" 'ยังไม่ครบ
        ElseIf PrefixTH = 5 Then

        End If

        lblTHName.Text = NameTh1
        lblENName.Text = NameEn1
        lblUniqueID.Text = UniqueID
        lblNational.Text = Nationality

        lblIncome.Text = IncomeSource1

        If Not IncomeSource2 = 0 Then
            lblIncome.Text = ", " + IncomeSource2
        End If

        If Not IncomeSource3 = 0 Then
            lblIncome.Text = ", " + IncomeSource3
        End If


        'If Not qryCust(0).cust.NGOCHECK1 Is Nothing Then
        '    If qryCust(0).cust.NGOCHECK1 = 1 Then
        '        lblNPO1.Text = "X"
        '    ElseIf qryCust(0).cust.NGOCHECK1 = 2 Then
        '        lblNPO2.Text = "X"
        '    End If
        'End If

        'If Not qryCust(0).cust.COMPCHECK1 Is Nothing Then
        '    If qryCust(0).cust.COMPCHECK1 = 1 Then
        '        lblRegis1.Text = "X"
        '    ElseIf qryCust(0).cust.COMPCHECK1 = 2 Then
        '        lblRegis2.Text = "X"
        '    ElseIf qryCust(0).cust.COMPCHECK1 = 3 Then
        '        lblRegis3.Text = "X"
        '    End If
        'End If




    End Sub


End Class
